package com.portal.framework.exception.handler;

import org.apache.commons.lang.exception.ExceptionUtils;

import com.portal.framework.util.ClassUtil;

public abstract class AbstractExceptionHandler implements ExceptionHandler {
	protected Class<? extends Throwable> exceptionClass;
	protected String stackTraceInfo;

	public void setExceptionClass(Class<? extends Throwable> exceptionClass) {
		this.exceptionClass = exceptionClass;
	}

	public Class<? extends Throwable> getExceptionClass() {
		return exceptionClass;
	}

	public abstract void handle(Throwable e) throws Throwable;

	public boolean isMatch(Throwable e) {
		if (getExceptionClass() == null || e == null) {
			return false;
		}
		if (e.getClass().equals(exceptionClass)) {
			return true;
		}
		return ClassUtil.isExtendFrom(e.getClass(), exceptionClass);
	}

	protected String getStackTraceInfo(Throwable e) {
		return ExceptionUtils.getFullStackTrace(e);
	}
}
